home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASCSRC.ZIP / DYNREC.PAS < prev    next >
Pascal/Delphi Source File  |  1988-01-15  |  2KB  |  71 lines

  1.                                 (* Chapter 12 - Program 4 *)
  2. program A_Dynamic_Storage_Record;
  3.  
  4. const  Number_Of_Friends = 50;
  5.  
  6. type Full_Name = record
  7.       First_Name : string[12];
  8.       Initial    : char;
  9.       Last_Name  : string[15];
  10.       end;
  11.  
  12.      Date      = record
  13.       Day        : byte;
  14.       Month      : byte;
  15.       Year       : integer;
  16.       end;
  17.  
  18.      Person_Id = ^Person;
  19.      Person    = record
  20.       Name       : Full_Name;
  21.       City       : string[15];
  22.       State      : string[2];
  23.       Zipcode    : string[5];
  24.       Birthday   : Date;
  25.       end;
  26.  
  27. var   Friend             : array[1..Number_Of_Friends] of Person_Id;
  28.       Self,Mother,Father : Person_Id;
  29.       Temp               : Person;
  30.       Index              : byte;
  31.  
  32. begin  (* main program *)
  33.    New(Self);   (* create the dynamic variable *)
  34.    Self^.Name.First_Name := 'Charley';
  35.    Self^.Name.Initial    := 'Z';
  36.    Self^.Name.Last_Name  := 'Brown';
  37.    with Self^ do begin
  38.       City := 'Anywhere';
  39.       State := 'CA';
  40.       Zipcode := '97342';
  41.       Birthday.Day := 17;
  42.       with Birthday do begin
  43.          Month := 7;
  44.          Year := 1938;
  45.       end;
  46.    end;    (* all data for self now defined *)
  47.  
  48.    New(Mother);
  49.    Mother := Self;
  50.    New(Father);
  51.    Father^ := Mother^;
  52.    for Index := 1 to Number_Of_Friends do begin
  53.       New(Friend[Index]);
  54.       Friend[Index]^ := Mother^;
  55.    end;
  56.  
  57.    Temp := Friend[27]^;
  58.    Write(Temp.Name.First_Name,' ');
  59.    Temp := Friend[33]^;
  60.    Write(Temp.Name.Initial,' ');
  61.    Temp := Father^;
  62.    Write(Temp.Name.Last_Name);
  63.    Writeln;
  64.  
  65.    Dispose(Self);
  66. {  Dispose(Mother); } (* since Mother is lost, it cannot
  67.                          be disposed of                  *)
  68.    Dispose(Father);
  69.    for Index := 1 to Number_Of_Friends do
  70.       Dispose(Friend[Index]);
  71. end. (* of main program *)